package BaseUserController

import (
	"github.com/gin-gonic/gin"
	"learn/app/controllers/cc"
	"learn/app/services/baseUserService"
)

type Menu struct {
	cc.BaseController
	ID       int64  `json:"id" one:"gte=0" two:"require,gte=0"`
	MenuName string `json:"menu_name" gorm:"menu_name"` // 菜单
	MenuPath string `json:"menu_path" gorm:"menu_path"` // 菜单路径
	Status   int8   `json:"status" gorm:"status"`       // 菜单状态：1 正常，2 关闭
	Order    int8   `json:"order" gorm:"order"`         // 排序
}

func (obj *Menu) Add(c *gin.Context) {
	userStruct := Menu{}
	//
	//form, err := c.MultipartForm()
	//if err != nil {
	//
	//}
	//
	//for _,f:= range form.File["upload[]"]{
	//	c.SaveUploadedFile()
	//}

	if ok := cc.BindParamAndCheckAndExpectField(c, &userStruct, "id"); ok == false {
		return
	}
	res, _ := new(baseUserService.Menu).Add(obj.ToMap(userStruct))
	cc.Return_with_code(res, c)
}

func (obj *Menu) Update(c *gin.Context) {
	userStruct := Menu{}
	if ok := cc.BindParamAndCheckAndExpectField(c, &userStruct); ok == false {
		return
	}
	res, _ := new(baseUserService.Menu).Update(obj.ToMap(userStruct))
	cc.Return_with_code(res, c)
}

func (obj *Menu) List(c *gin.Context) {
	res, count := new(baseUserService.Menu).List()
	cc.Return_success(c, cc.WithData(res), cc.WithCount(count))
}

func (obj *Menu) Del(c *gin.Context) {
	userStruct := Role{}
	if ok := cc.BindParamAndCheckAndExpectField(c, &userStruct, "id"); ok == false {
		return
	}

	res, _ := new(baseUserService.Menu).Del(obj.ToMap(userStruct))
	cc.Return_with_code(res, c)
}
